﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ServerConnection.ShopServiceReference;

namespace ShopShell
{
    /// <summary>
    /// Interaction logic for Auth.xaml
    /// </summary>
    public partial class Auth : Window
    {

        public User User { get; private set; }

        public Auth()
        {
            InitializeComponent();
            User = null;
        }

        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btn_ok_Click(object sender, RoutedEventArgs e)
        {
            string login = tb_login.Text;
            string password = tb_password.Password;

            if (!String.IsNullOrWhiteSpace(login) && !String.IsNullOrWhiteSpace(password))
            {
                User user = ServerConnection.Service.Instance.Login(login, password, 0);
                if (user != null && user.Id != 0 && user.PlaceId.HasValue)
                {
                    User = user;
                    DialogResult = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Access denied");
                }
            }
            else
            {
                MessageBox.Show("Login or password cant be empty!");
            }
        }
    }
}
